package ${packName};

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;

import com.opensymphony.xwork2.Preparable;
import com.simpleframe.web.action.CrudActionSupport;
import ${pojoClassName};
import ${serviceClassName};

@Scope("prototype")
@Namespace("/${pojoInstanceName}")
@Action("/${pojoInstanceName}")
public class ${name} extends CrudActionSupport  {
	@Autowired
	private ${serviceName} ${serviceInstanceName};
	private ${pojoName} ${pojoInstanceName};

	@Override
	public String main(){
		return MAIN;
	}
	
	@Override
	public String grid() throws Exception {
		page = ${serviceInstanceName}.getPage(getSearcher());
		return GRID;
	}
	
	@Override
	public String create() throws Exception {
		setSaveMode();
		${pojoInstanceName} = new ${pojoName}();
		
		return EDIT;
	}
	
	@Override
	public String edit() throws Exception {
		setUpdateMode();
		${pojoInstanceName} = ${serviceInstanceName}.getById(${pojoInstanceName}.getId());
		return EDIT;
	}
	
	@Override
	public String save() throws Exception {
		${serviceInstanceName}.create(${pojoInstanceName});
		return success("添加成功");
	}
	
	public String update() throws Exception {
		
		${serviceInstanceName}.update(${pojoInstanceName});
		return success("修改成功");
	}
	
	public void prepareUpdate() throws Exception {
		${pojoInstanceName} = ${serviceInstanceName}.getById(getId());
	}
	
	public void validator() throws Exception {
		System.out.println("执行验证");
	}
	
	@Override
	public String delete() throws Exception {
		${serviceInstanceName}.deletes(ids);
		addMessage("删除成功");
		return null;
	}
	
	//setters and getters
	
	public void set${pojoName}(${pojoName} ${pojoInstanceName}) {
		this.${pojoInstanceName} = ${pojoInstanceName};
	}
	
	public ${pojoName} get${pojoName}() {
		return ${pojoInstanceName};
	}
}
